//获取题集列表
function getTopicSet() {
    $.get("http://139.199.200.112/dtpr/index.php?exam-teach-questions-examsetlist",function (data) {
        var data=JSON.parse(data).data;
        var parent=$("#select-test");
        parent.empty();

        for(var i=0;i<data.length;i++){
            parent.append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
        }

        parent.change(selectSet);
        selectSet();
    });
}
getTopicSet();

//给table增加一行
function addLine(data,url) {
    var tbody=$(".test-quesiont").find("tbody");
    var line=$("<tr>\n" +
        "    <td>"+data.id+"</td>\n" +
        "    <td>"+data.subject+"</td>\n" +
        "    <td>"+data.volume+"</td>\n" +
        "    <td>"+data.section+"</td>\n" +
        "    <td><a>"+data.question+"</a></td>\n" +
        questionType[data.type-1] +
        questionLevel[data.level-1] +
        "    <td><button class='btn btn-danger'><span class='glyphicon glyphicon-remove'></span></button> </td>\n" +
        "</tr>");

    line.find(".btn").click(deleteTopic);
    line.find("a").click(openDetail);

    tbody.append(line);
}

//删除题集
function deleteTopicSet() {
    var value=$("#select-test").val();
    console.log(value);
    $.get("http://139.199.200.112/dtpr/index.php?exam-teach-questions-delexam",{id:value},function (data) {
        message(data);
        getTopicSet();
    })
}

//修改题集名
function editorSetName(){
    var json={"id":$("#set-id").val(),"name":$("#set-name").val()}

    console.log(json);

    $.get("http://139.199.200.112/dtpr/index.php?exam-teach-questions-modifyexam",json,function (data) {
        message(data);
        getTopicSet();
    })
}

//删除题目
function deleteTopic() {
    if(!confirm("你确定要删除该题目吗？删除后不可恢复！")){
        return;
    }

    var id=getTdId(this);
    var json={"id":$("#set-id").val(),"questionid":id};
    $.get("http://139.199.200.112/dtpr/index.php?exam-teach-questions-delquestion",json,function (data) {
        data=JSON.parse(data);

        if(data.code==0){
            selectSet();
        }else {
            alert(data.msg);
        }
    })
}

//选择题集
function selectSet() {
    var url="http://139.199.200.112/dtpr/index.php?exam-teach-questions-examinfolist";
    var id=$("#select-test").val();
    var json={"id":id,"page":1};
    var pageEle=".topic-page";
    var bodyEle=".table tbody";
    flushTable(url,JSON.stringify(json),pageEle,bodyEle);

    $("#set-id").val(id);
    $("#set-name").val($("#select-test").find("option:selected").text());
}

//打开题目详情的modal
function openDetail() {
    $("#modal-topic").modal();
    var id=getTdId(this);

    $.get("http://139.199.200.112/dtpr/index.php?exam-teach-questions-questioninfo",{"id":id},function (data) {
        data=JSON.parse(data).data;

        var parent=$("#modal-topic").find(".modal-body");
        setTopicDetail(data,parent);
    })
}

//设置选择题答案
function multipleAnswer() {

}

//设置填空题答案
function completionAnswer() {

}

function tfngAnswer(){

}